/**
@file
    PongView.java
@brief
    Copyright 2008 Creative Crew. All rights reserved.
@author
    William Chang
@version
    0.1
@date
    - Created: 2007-11-21
    - Modified: 2007-11-26
    .
@note
    References:
    - General:
        - http://code.google.com/android/reference/android/view/View.html
        - http://code.google.com/android/reference/android/os/Handler.html
        .
    .
*/

package diehard.sandbox;

import android.content.Context;
import android.content.res.*;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

/**
 * Class PongView.
 * @author William Chang
 */
public class PongView extends TileView {
    /** Argument constructor. Constructs based on inflation from XML. */
    public PongView(Context context, AttributeSet attrs) {
        // Mandatory call to the super class.
        super(context, attrs);
        // Instantiate this.
        if(!instantiateThis()) return;
    }
    /** Argument constructor. */
    public PongView(Context context, AttributeSet attrs, int defStyle) {
        // Mandatory call to the super class.
        super(context, attrs, defStyle);
        // Instantiate this.
        if(!instantiateThis()) return;
    }
    /** Instantiate this. */
    public boolean instantiateThis() {
        setFocusable(true);

        _state = READY;
        _timeDelay = 10;
        _velocity = 10;
        _direction = HALT;
        _nextDirection = HALT;

        _ballDirection = 2;
        _ballVelocityX = 1;
        _ballVelocityY = 1;

        return true;
    }
    /** Initialize tiles. */
    public void initalizeTiles() {
        // Tile Studio - Definition: <TileSetIdentifier> <MapIdentifier>
        _map1 = new Entity("level1", Entity.STAGE);
        // Tile Studio - Definition: <TileNumber:"%2d">
        _map1.setMapTile(_map1Tile, 34, 159);
        // Tile Studio - Definition: <BoundMapValue>
        _map1.setMapBoundAndCode(_map1BoundAndCode);
        // Tile Studio - Definition: <TileWidth>, <TileHeight>
        _map1.setTileSet(getContext().getResources().getDrawable(R.drawable.pong_tileset), 20, 16);
        // Set main entity.
        setEntityMain(_map1);

        // Tile Studio - Definition: <TileSetIdentifier> <MapIdentifier>
        _ball1 = new Entity("ball", Entity.ITEM);
        // Tile Studio - Definition: <TileNumber:"%2d">
        _ball1.setMapTile(_map2Tile, 5, 9);
        // Tile Studio - Definition: <BoundMapValue>
        _ball1.setMapBoundAndCode(_map2BoundAndCode);
        // Tile Studio - Definition: <TileNumber>, <FrameCount>, <BoundMapValue>
        _ball1.addMapSequence(new EntityAnimation(1, _map2Sequence1, 12));
        // Tile Studio - Definition: <TileWidth>, <TileHeight>
        _ball1.setTileSet(getContext().getResources().getDrawable(R.drawable.ball_tileset), 20, 20);
        // Add entity.
        addEntity(_ball1);
    }
    /** Set state (mode). */
    public void setState(int newState) {
        int oldState = _state;
        _state = newState;

        if(newState == RUNNING & oldState != RUNNING) {
            _tvStatus.setVisibility(View.INVISIBLE);
            renderOneFrame();
            return;
        }

        Resources res = getContext().getResources();
        CharSequence s = "";
        if(newState == PAUSE) {
            s = res.getText(R.string.state_pause);
        }
        if(newState == READY) {
            initalizeTiles();
            s = res.getText(R.string.state_ready);
        }
        if(newState == LOSE) {
            // TODO
        }
        _tvStatus.setText(s);
        _tvStatus.setVisibility(View.VISIBLE);
    }
    /** Set text vew. */
    public void setTextView(TextView v) {
        _tvStatus = v;
    }
    /** Event on key down. */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            if(_state == READY || _state == LOSE) {
                setState(RUNNING);
                renderOneFrame();
                return true;
            }
        }
        if(keyCode == KeyEvent.KEYCODE_DPAD_UP) {
            if(_direction != SOUTH) {
                _nextDirection = NORTH;
            }
            return true;
        }
        if(keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
            if(_direction != NORTH) {
                _nextDirection = SOUTH;
            }
            return true;
        }
        if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
            if(_direction != EAST) {
                _nextDirection = WEST;
            }
            return true;
        }
        if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
            if(_direction != WEST) {
                _nextDirection = EAST;
            }
            return true;
        }

        return super.onKeyDown(keyCode, event);
    }
    /** Move view. */
    private void moveView() {
        _direction = _nextDirection;
        int x = getOffsetX();
        int y = getOffsetY();

        switch(_direction) {
            case EAST: {
                x -= _velocity;
                break;
            }
            case WEST: {
                x += _velocity;
                break;
            }
            case NORTH: {
                y += _velocity;
                break;
            }
            case SOUTH: {
                y -= _velocity;
                break;
            }
            case HALT: {
                break;
            }
        }
        setViewOffset(x, y);
        _nextDirection = HALT;
    }
    /** Move ball. */
    private void moveBall() {
        _mapTilesInViewWidth = (int)Math.floor(getWidth() / _map1.getTileWidth());
        _mapTilesInViewHeight = (int)Math.floor(getHeight() / _map1.getTileHeight());
        
        if(_ballDirection == 0) {
            _ballX -= _ballVelocityX;
            _ballY -= _ballVelocityY;
        } else if(_ballDirection == 1) {
            _ballX += _ballVelocityX;
            _ballY -= _ballVelocityY;
        } else if(_ballDirection == 2) {
            _ballX += _ballVelocityX;
            _ballY += _ballVelocityY;
        } else if(_ballDirection == 3) {
            _ballX -= _ballVelocityX;
            _ballY += _ballVelocityY;
        }

        if(_ballDirection == 0 && _ballX < 0) {
            _ballDirection = 1;
        } else if(_ballDirection == 0 && _ballY < 0) {
            _ballDirection = 3;
        } else if(_ballDirection == 1 && _ballY < 0) {
            _ballDirection = 2;
        } else if(_ballDirection == 1 && _ballX > _mapTilesInViewWidth) {
            _ballDirection = 0;
        } else if(_ballDirection == 2 && _ballY > _mapTilesInViewHeight) {
            _ballDirection = 1;
        } else if(_ballDirection == 2 && _ballX > _mapTilesInViewWidth) {
            _ballDirection = 3;
        } else if(_ballDirection == 3 && _ballY > _mapTilesInViewHeight) {
            _ballDirection = 0;
        } else if(_ballDirection == 3 && _ballX < 0) {
            _ballDirection = 2;
        }
    }
    /** Render one frame. */
    private void renderOneFrame() {
        if(_state == RUNNING) {
            long timeNow = System.currentTimeMillis();

            if(timeNow - _timeActed > _timeDelay) {
                moveView();
                moveBall();
                _ball1.getMapSequenceList()[0].setPositions(_ballX, _ballY);

                _timeActed = timeNow;
            }
            _loopHandler.sleep(_timeDelay);
        }
    }

    private Entity _map1;
    private Entity _ball1;

    private int _mapTilesInViewWidth;
    private int _mapTilesInViewHeight;
    
    /// Ball horizontal position, primitive data type.
    private int _ballX;
    /// Ball vertical position, primitive data type.
    private int _ballY;
    /// Ball horizontal velocity, primitive data type.
    private int _ballVelocityX;
     /// Ball vertical velocity, primitive data type.
    private int _ballVelocityY;
     /// Ball direction, primitive data type.
    private int _ballDirection;

    /// Output widget.
    private TextView _tvStatus;
    /// Frame delay time.
    private long _timeDelay;
    /// Time acted.
    private long _timeActed;
    /// State (mode).
    private int _state;
    /// Direction.
    private int _direction;
    /// Next direction.
    private int _nextDirection;
    /// Velocity.
    private int _velocity;

    // Enum: Direction of .
    private static final int HALT = 0;
    private static final int NORTH = 1;
    private static final int SOUTH = 2;
    private static final int EAST = 3;
    private static final int WEST = 4;

    // Enum: State (mode) of application. (static final ints are used instead of an enum for performance reasons)
    public static final int PAUSE = 0;
    public static final int READY = 1;
    public static final int RUNNING = 2;
    public static final int LOSE = 3;

    /** Simple handler to render animation. **/
    private LoopHandler _loopHandler = new LoopHandler();
    /** Setup target and the sleep() function to cause an renderOneFrame/invalidate to occur at a later time. */
    class LoopHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            PongView.this.renderOneFrame();
            PongView.this.invalidate();
        }
        /** Sleep in milliseconds. */
        public void sleep(long timeDelay) {
            this.removeMessages(0);
            sendMessageDelayed(obtainMessage(0), timeDelay);
        }
    };

    private int[][] _map1Tile =
    {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0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 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,48,37, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,49,49,49, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0,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0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 5, 6, 7, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,49, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0,11,12,13, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,50, 0, 0,51,52, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,17, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 9,
       10, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,53,54,54,54,55, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,17, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0,11,12,13, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 0, 0, 0, 0,14,15,
       16,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,56,57,58,59,60,59,61, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,17, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 9,10, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 8, 9,10, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0, 0,18,19,
       20,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,62,63,58,59,59,60,61, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,17, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0, 0, 0,11,12,13, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,14,15,16,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0,14,15,16,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,11,12,13, 0, 0, 0, 0, 0,21,
        0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,64,65,66,67,59,59,61, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0,17, 0,22,23, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,18,19,20,17, 0, 0, 0, 0, 0, 0, 0, 0, 0,51,52,
        0, 0, 0,11,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0,18,19,20,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0,21,
        0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,68,69,70,71,59,72,61, 0, 0, 0,73,74, 0,
        0, 0, 0, 0,17, 0,75,76, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0,77,78, 0, 0, 0, 0, 0,17, 0, 0, 0, 0,
        0,79, 0, 0, 0, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0, 0, 0, 0,53,54,54,54,55,
        0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,51,52,
        0, 0, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0,21,
        0,17, 0, 0, 0, 0, 0, 0, 0, 0,48,37,68,70,69,71,59,59,61, 0,79, 0,80,81, 0,
       82,83, 0,48,84, 0,33,29, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0,85,86, 0, 0, 0, 0, 0,17, 0, 0, 0, 0,
       53,54,54,55, 0, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0,56,57, 0,58,59,60,59,61,
       50, 0, 0, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,53,54,54,
       54,55, 0, 0, 0,49, 0, 0,21, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,77,78, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0,21,
        0,17, 0,22,23,64,65,65,65,65,65,66,87,69,69,88,65,65,65,65,65,65,65,65,65,
       65,65,65,65,65,65,65,65,65},
      {73,74, 0, 0, 0, 0, 0, 0, 0, 0,17, 0,64,65,89, 0, 0, 0, 0, 0,17, 0, 0, 0, 0,
       58,59,60,61, 0, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0,62,63, 0,58,59,59,60,90,
       55, 0, 0, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,58,59,59,
       60,61, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0,91,92, 0, 0, 0, 0, 0,85,86, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0, 0,21,
        0,17, 0,33,29,68,69,69,69,70,69,69,69,69,69,69,70,69,69,69,93,69,69,69,69,
       69,69,69,69,69,70,69,69,69},
      {80,81, 0, 0, 0, 0, 0, 0,79, 0,94,35,68,70,95, 0, 0, 0, 0, 0,17, 0, 0, 0, 0,
       58,59,59,61, 0, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0,64,65,66,66,67,59,59,59,
       61, 0, 0, 0,17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,58,60,59,
       59,61, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0,96,97,64,65,65,65,65,65,89, 0, 0,
        0, 0, 0, 0,22,23, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,17, 0, 0, 0, 0, 0,98,99,
        0,17, 0,75,76,68,69,69,69,69,69,69,69,69,69,69,69,69,70,69,69,69,69,69,69,
       70,70,69,69,69,69,70,69,69},
      {66,66,65,65,66,65,65,65,65,66,66,65,87,69,95, 0, 0, 0, 0, 0,17,24,25,100,
        0,58,60,59,61, 0,101,22,23, 0, 0, 0,21, 0,17, 0, 0, 0,68,69,69,70,71,59,
       59,72,61, 0, 0, 0,17, 0, 0, 0,24,25,100, 0, 0, 0, 0, 0, 0, 0, 0, 0,102,103,
       58,59,59,59,61, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0, 0,104,105,68,69,69,69,69,
       70,95, 0, 0, 0, 0, 0, 0,33,29, 0, 0, 0, 0, 0, 0, 0,22,23, 0, 0,17,24,25,100,
        0, 0,64,65,65,65,65,65,65,87,69,69,69,70,69,69,70,69,69,69,69,69,69,69,69,
       69,69,69,70,69,69,69,69,69,69,69,69,69},
      {69,69,69,69,69,69,69,69,69,69,93,69,69,69,95,106,107, 0, 0,48,84,108,31,109,
        0,58,59,59,110,52,49,33,29, 0, 0,111,112, 0,17, 0,48,37,68,70,69,69,71,59,
       59,59,61, 0, 0,113,114, 0, 0, 0,108,31,109, 0, 0, 0, 0, 0, 0, 0, 0, 0,75,
       76,58,59,59,115,61, 0, 0, 0, 0, 0, 0,21, 0,17, 0, 0,64,65,65,87,69,69,69,
       69,69,95, 0,106,107, 0, 0, 0,75,76, 0, 0, 0, 0, 0, 0, 0,33,29, 0,48,84,108,
       31,109, 0, 0,68,69,70,69,69,69,70,69,69,69,69,69,69,69,69,70,69,69,69,69,
       70,69,69,69,69,69,69,70,69,69,69,69,69,69,69,69},
      {69,69,70,69,69,69,69,70,69,69,69,69,69,69,88,65,66,65,65,65,65,65,66,65,66,
       66,66,66,66,66,66,116,117,118,118,119,65,65,66,65,65,66,87,69,93,69,88,65,
       65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,65,120,118,118,118,118,121,
       122,66,66,66,67,110,52, 0, 0, 0, 0,111,112, 0,17, 0,79,68,69,70,69,69,69,
       69,70,69,88,65,66,66,120,118,118,121,122,66,120,118,118,118,119,66,66,66,
       66,65,65,65,66,65,66,65,87,69,69,69,69,69,69,69,69,69,70,69,93,69,69,69,69,
       69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69},
      {69,69,69,69,93,69,69,69,69,69,69,69,69,70,69,69,69,69,69,69,93,69,69,69,70,
       69,69,69,70,69,69,123,124,125,125,126,69,69,69,93,69,69,69,70,69,69,69,69,
       69,69,69,93,69,69,69,69,69,69,69,69,69,70,69,69,69,127,125,125,125,125,128,
       129,69,69,69,88,66,66,66,66,65,65,65,65,65,66,65,65,87,69,69,69,69,69,70,
       69,69,69,69,69,69,130,131,125,128,129,69,127,125,125,125,126,93,69,69,69,
       69,70,69,69,70,69,69,69,69,69,69,70,69,69,93,69,70,69,69,69,69,69,69,69,69,
       70,69,69,93,69,69,69,70,69,69,93,69,69,69,69,69,69,69},
      {69,70,69,93,69,69,69,69,70,69,69,70,69,69,69,69,69,69,70,69,69,69,70,69,69,
       69,69,69,69,69,70,123,132,125,125,126,69,70,70,69,69,70,69,69,69,69,69,69,
       93,69,69,69,69,69,70,69,69,93,69,69,69,69,69,93,69,130,131,125,125,125,133,
       134,69,93,69,69,70,69,69,69,69,69,69,70,69,69,69,69,69,69,69,93,69,69,69,
       69,69,69,69,69,70,130,135,125,133,136,70,127,125,137,131,126,69,69,69,70,
       69,69,69,69,69,70,69,69,69,69,70,69,69,69,69,69,69,69,69,69,69,69,69,69,70,
       69,69,69,69,69,69,70,69,69,69,69,69,69,70,69,69,69,69},
      {69,69,69,69,69,69,69,70,69,69,69,69,69,69,93,69,69,70,69,69,69,69,69,93,69,
       69,69,70,69,69,69,123,124,125,125,126,69,69,69,69,93,69,69,69,69,69,93,69,
       69,69,69,69,69,69,69,69,69,69,69,93,69,69,69,69,70,130,135,138,139,125,128,
       129,69,69,69,69,69,69,69,69,93,69,69,69,69,70,69,69,69,69,70,69,69,69,69,
       69,69,69,70,69,69,130,140,125,128,141,69,127,125,142,140,126,69,70,69,69,
       69,69,69,69,69,69,69,93,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,
       69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,70},
      {69,69,69,70,69,70,69,69,69,70,69,69,69,69,69,69,69,69,69,70,69,69,69,69,69,
       69,70,69,69,69,69,123,132,125,125,126,70,69,69,69,69,69,93,69,69,69,69,69,
       70,69,93,69,93,69,69,69,69,69,69,69,69,93,69,69,69,130,140,143,144,125,133,
       129,70,69,69,69,69,69,69,69,69,69,70,69,69,69,69,69,69,69,69,69,69,69,69,
       69,93,69,69,69,69,130,135,125,133,141,69,127,125,145,135,126,69,69,69,69,
       69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,
       69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0},
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
        0, 0, 0, 0, 0, 0, 0, 0, 0}};

    private int[][] _map1BoundAndCode =
    {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,33024,0,0,0,0,0,0,0,0,0,0,768,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,45056,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49152,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4096,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4864,0,0,0,0,15,15,15,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4096,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,45056,0,0,0,0,0,0,0,0,0,0,4096,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33024,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,768,0,0,0,33024,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,256,0,512,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,45056,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,6912,6912,6912,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,256,4864,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,4352,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,33024,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4864,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,256,0,512,4864,256,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,33024,0,0,0,0,0,0,0,0,0,0,0,0,0,4352,0,0,0,0,0,0,45056,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4864,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,256,0,512,0,0,0,0,0,
        4864,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4352,0,0,0},
       {0,0,0,0,0,0,0,0,0,6912,6913,6912,0,4864,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4352,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6912,6913,6912,0,0,0,0,4864,0,
        0,0,0,0,0,1,1,1,1,1,0,0,0,0,4352,0,0,0,0,0,4352,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,256,0,512,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,256,0,512,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,256,0,512,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,45056,0,0,0,0,0,0,0,0,0,256,0,512,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,4352,0,0,0,0,0,4352,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6912,6912,6912,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,6912,6913,6912,0,0,0,0,0,0,0,0,0,0,0,0,0,256,0,512,0,0,0,0,0,0,
        0,0,0,0,0,33024,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6912,6913,6912,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6912,6913,6912,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,33024,0,0,0,0,0,0,0,0,0,0,0,4352,0,0,0,0,0,0,0,0,0,0,
        0,0},
       {0,0,0,0,0,0,4096,4096,4096,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6912,6913,6912,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4864,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,3,1,1,9,0,0,0,0,0,0,0,0,0,65024,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4352,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,1024,0,0,0,0,0,0,0,0,0,0,0,0,0,256,4864,0,0,0,0,0,0,0,0,0,0,33024,0,0,
        0,0,0,45056,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33024,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,2,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,256,0,0,32768,0,256,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8192,0,0,
        0,0,0,0,0,0,49152,0,0,0,0,0,0,0,0,0,0,0,0,0,4864,256,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        2,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33024,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,33024,0,0,0,0,0,0,0,
        0,0,1,1,1,1,1,0,0,0,15,0,0,0,0,0,0,0,0,4864,0,0,0,256,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,1,1,1,1,1,1,0,0,0,0,
        1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
       {0,0,0,0,0,0,0,0,0,0,0,0,3,1,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,33024,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,4864,0,0,0,0,0,0,0,0,0,0,0,0,0,0,256,0,0,32768,0,0,0,0,256,0,0,0,0,
        0,0,0,45056,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1024,0,0,0,2,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,61440,0,0,0,0,0,0,0,0,2,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,3,1,1,1,9,0,0,0,0,0,0,0,0,0,0,0,256,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,1,1,1,1,1,9,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49152,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {1,1,1,1,1,1,1,1,1,1,1,1,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,256,0,0,2,0,0,0,8,0,256,512,0,0,0,0,0,0,0,0,49152,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,8,256,256,0,0,0,0,
        0,33280,4352,0,0,0,0,0,33280,0,0,0,0,0,0,0,512,0,0,3,1,1,1,1,1,1,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,32768,0,0,0,49152,49152,0,0,0,0,0,0,0,15,
        0,0,0,256,0,0,0,0,32768,0,0,2,0,0,0,8,0,49152,49152,0,0,0,0,0,0,0,0,49152,
        0,0,0,0,0,8192,0,0,0,0,0,0,0,0,0,0,15,0,0,0,33280,0,0,0,0,33280,0,0,0,3,1,
        1,0,0,0,0,0,0,8,49152,49152,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,49152,
        0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,0,0,0,3,1,
        1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,9,0,0,0,0,0,3,1,1,
        1,9,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,1,1,1,9,0,0,0,3,1,9,0,0,0,
        3,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,7937,7937,
        7937,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,7937,7937,
        7937,7937,7937,2,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
        0,8,7937,7937,7937,2,0,8,7937,7937,7937,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,2,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,2,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,2,0,8,0,0,0,
        2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,2,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,2,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,2,0,8,0,0,0,
        2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,2,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,2,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,2,0,8,0,0,0,
        2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0},
       {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
        0,0,0,0,0,0,0,0,0,0,0}};

    private int[][] _map2Tile =
        {{ 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0,-1, 0, 1, 2, 3, 2, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0},
        { 0, 0, 0, 0, 0, 0, 0, 0, 0}};
    private int[][] _map2BoundAndCode =
        {{0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0},
        {0,0,0,256,256,256,256,0,0},
        {0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0}};
    private int[] _map2Sequence1 =
        {1, 1, 256, 2, 1, 256, 3, 1, 256, 2, 1, 256};
}
